home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 May: Tool Chest / Developer CD Series May 1996 (Tool Chest) (Apple Computer) (1996).iso / Sample Code / Snippets / QuickDraw / Restore Screen Cluts / Exceptions.a < prev    next >
Encoding:
Text File  |  1993-01-18  |  2.4 KB  |  69 lines  |  [TEXT/MPS ]

  1. ********************************************************************************
  2. *
  3. * Apple Macintosh Developer Technical Support
  4. *
  5. * Exception-handling routines
  6. *
  7. * Program: GMundo
  8. * File:    Exceptions.a
  9. *
  10. * by:      Forrest Tanaka
  11. *
  12. * Copyright © 1988-1992 Apple Computer, Inc.
  13. * All rights reserved.
  14. *
  15. ********************************************************************************
  16.  
  17.         CASE        ON
  18.  
  19. ********************************************************************************
  20. * short ExceptionEntry(ExceptionPtr environment,
  21. *                      long         *exceptionType,
  22. *                      long         *exceptionCode);
  23. *
  24. * The exceptionType and exceptionCode pointers are saved in the environment
  25. * parameter, along with all the registers except D0, D1, A0, and A5.
  26. ********************************************************************************
  27.  
  28.         SEG        'Main'
  29. ExceptionEntry    FUNC        EXPORT
  30.         MOVEA.L        (SP)+,A1        ;Save ret addr
  31.         MOVEA.L        (SP),A0            ;Get ExceptionRec ptr
  32.         MOVE.L        $0004(SP),(A0)+        ;Save exceptionType ptr
  33.         MOVE.L        $0008(SP),(A0)+        ;Save exceptionCode ptr
  34.         MOVEM.L        D2-D7/A1-A4/A6/SP,(A0)    ;Save registers,PC,SP
  35.         MOVEQ        #$0,D0            ;Set return val to 0
  36.         JMP        (A1)            ;Return to caller
  37.         ENDFUNC
  38.  
  39. ********************************************************************************
  40. * void Exception(ExceptionPtr environment,
  41. *                long         exceptionType,
  42. *                long         exceptionCode);
  43. *
  44. * The exceptionType and exceptionCode parameters are placed into the
  45. * corresponding locations specified by the environment parameter.  The registers
  46. * are then restored from the contents of the environment parameter.  The flow
  47. * of control then jumps to the location that was saved in the environment
  48. * parameter.
  49. ********************************************************************************
  50.  
  51. Exception    PROC        EXPORT
  52.         MOVEA.L        $0004(SP),A0        ;Get ExceptionRec ptr
  53.         MOVE.L        (A0),D0            ;Get exceptionType ptr
  54.         BEQ.S        @getExcCode        ;If nil, skip setting
  55.         MOVEA.L        D0,A1            ;Need in A-reg to set
  56.         MOVE.L        $0008(SP),(A1)        ;Set exceptionType
  57. @getExcCode
  58.         MOVE.L        $0004(A0),D0        ;Get exceptionCode ptr
  59.         BEQ.S        @restRegs        ;If nil, skip setting
  60.         MOVEA.L        D0,A1            ;Need in A-reg to set
  61.         MOVE.L        $000C(SP),(A1)        ;Set exceptionCode
  62. @restRegs
  63.         MOVEQ        #$F,D0            ;Set return val to -1
  64.         MOVEM.L        $0008(A0),D2-D7/A1-A4/A6/SP    ;…
  65.                             ;Restore registers
  66.         JMP        (A1)            ;Go to ExceptionEntry
  67.         ENDPROC
  68.  
  69.         END